package esb.chapter8.errorhandling.bean;

import javax.annotation.Resource;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;

import org.apache.servicemix.MessageExchangeListener;

public class ErrorComponent implements MessageExchangeListener {

	@Resource
	private DeliveryChannel channel;

    public void onMessageExchange(MessageExchange exchange) throws MessagingException {
        exchange.setStatus(ExchangeStatus.ERROR);
        exchange.setError(new NullPointerException("Exception thrown for test purposes!"));
        channel.send(exchange);
    }
}
